
package CSISL4pk;

import java.util.Locale;
import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;
//package de.vogella.jfreechart.swing.pie;


public class PieChart extends JFrame {

	//private static final long serialVersionUID = 1L;
        private String[] locations =
    {
        "Avenues", "Sugarhouse", "Liberty East", "Liberty West", "Trolley Square",
        "Central", "University", "Rose Park", "Glendale", "Foothill", "Capitol Hill", "Downtown"
    };

	public PieChart(String applicationTitle, String chartTitle, int[]crimes) {
        super(applicationTitle);
        // This will create the dataset 
        PieDataset dataset = createDataset(crimes);
        // based on the dataset we create the chart
        JFreeChart chart = createChart(dataset, chartTitle);
        // we put the chart into a panel
        ChartPanel chartPanel = new ChartPanel(chart);
        // default size
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        // add it to our application
        setContentPane(chartPanel);
    }
/** * Creates a sample dataset */

    private  PieDataset createDataset(int[]crimes) {
        
        DefaultPieDataset result = new DefaultPieDataset();
       
        for(int count=0;count<locations.length;count++)
        {
            result.setValue(locations[count], crimes[count]);
        }
   
        return result;
        
    }
/** * Creates a chart */

    private JFreeChart createChart(PieDataset dataset, String title) {
        
        JFreeChart chart = ChartFactory.createPieChart(
            title,  				// chart title
            dataset,                // data
            true,                   // include legend
            true,
            false
        );
        
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(0.5f);
        return chart;
    }
}